﻿using System;
using System.Collections.Generic;

using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using Rhino.Commons;

using Quiziqal.Domain;
using Quiziqal.Persistence;
using Quiziqal.Core.ForTesting;

namespace Quiziqal.Persistence.Specifications
{
    [TestFixture]
    public class when_saving_question : PersistenceTestBase
    {
        Question toDb;
        const string BODY = "What is the airspeed velocity of an unladen swallow?";

        protected override void EstablishContext()
        {
            toDb = new Question(BODY);
        }

        protected override void When()
        {
            Repository<Question>.Save(toDb);
            FlushSessionAndEvict(toDb);
        }

        [Test]
        public void question_can_be_retrieved()
        {
            Question fromDb = Repository<Question>.Get(toDb.Id);

            fromDb.ShouldNotBeNull("retrieved question should not be null");
            fromDb.ShouldNotBeTheSameAs(toDb, "object variables should not reference the same object");
        }
    }
}
